package org.example.repository;

import org.example.entity.Todo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface TodoRepository extends JpaRepository<Todo,Integer>, JpaSpecificationExecutor<Todo> {

    List<Todo> findByContentMd5(String md5);

    @Transactional
    @Modifying
    @Query(value="update todo  set status=(:status) where  id=(:id)",nativeQuery = true)
    int updateStatus(int id,String status);

    @Query(value="update todo  set deleted=1 where  id=(:id)",nativeQuery = true)
    int deleteTodo(int id);

    @Transactional
    @Modifying
    @Query(value = "update todo set deleted=1 where deleted=0",nativeQuery = true)
    int deleteComplete();

    List<Todo> findByDeleted(int deleted);



}
